import java.util.Scanner;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 666
 * Date: 2023-04-16
 * Time: 23:36
 */
public class test4 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()){
            String str = scanner.next();


            while (str.length()>1){
                int a=0;
                for (int i = 0; i < str.length(); i++) {
                    a+=str.charAt(i)-'0';

                }
                str=String.valueOf(a);
            }
            System.out.println(Integer.parseInt(str));
        }
    }
}
